import React, { useEffect, useState } from "react";
import { useLocation } from "react-router-dom";
import qs from "qs";
import axios from "axios";

const Index: React.FC = () => {
  const location = useLocation();
  const search = location.search.slice(1);
  const obj = qs.parse(search);
  const [message, setMessage] = useState('查询中...')

  const query = async () => {
    const resp =  await axios.get("/api/pay/result", {
      params: { trade_no: obj.trade_no, out_trade_no: obj.out_trade_no },
    });
    setMessage(resp.data.message)

  };
  useEffect(() => {
    query();
  }, []);

  return <div>支付结果: { message }</div>;
};

export default Index;
